<template>
  <div class="app">
  <stu v-on:getStuName="demo" :demo1="demo1" ref="student"></stu>
    <hr>
<!--    通过父组件给子组件传递函数类型的props实现：子给父传递数据-->
    <school :getName="getName" @click.native="show"></school>
  </div>
</template>


<script>
//汇总引入组件
import Stu from "@/components/Stu.vue";
import School from "@/components/School.vue";
export default {
  name:'App',
  components:{
    School,
    Stu
  },
  methods:{
    getName(val){
      console.log(val)
      return val
    },
    demo(name,...params){

      console.log('demo调用了,名字：'+name+params)
    },
    demo1(name,...params){

      console.log('demo1调用了,名字：'+name+params)
    },
    show(){
      alert('show')
    }

  },
  mounted() {
    this.$refs.student.$on('getStuName',this.demo)
    // 只执行一次
    // this.$refs.student.$once('getStuName',this.demo)
  }

}

</script>
<style>
.app{
  height: 600px;
  background-color: cadetblue;
}
</style>
